package app.v1.yd.domain.pojo;

import app.common.ar.Ar;
import com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDResponseBody;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.feizns.quickstart.ddl.annotation.Comment;
import com.gitee.feizns.quickstart.mybatis.plus.builder.annotation.Equal;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Entity;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 库存表
 * @author feizns
 * @since 2023/09/11
 */
@Entity
@Getter
@Setter
@ToString(callSuper = true)
@Accessors(chain = true)
@TableName(autoResultMap = true)
@NoArgsConstructor
@Comment("宜搭库存表")
public class YdInventoryStatement extends Ar<YdInventoryStatement> {

    /**
     * instance编号
     */
    @Equal
    @Comment("instance编号")
    @Column(unique = true)
    private String instanceId;

    /**
     * 商家编码
     */
    @Comment("商家编码")
    private String merchantCode;

    /**
     * 仓库名称
     */
    @Comment("仓库名称")
    private String warehouseName;

    /**
     * 库存量
     */
    @Comment("库存量")
    private BigDecimal inventory;

    /**
     * @param data {@link Map}
     */
    @SuppressWarnings("unchecked")
    public void from(GetFormDataByIDResponseBody data) {
        Map<String, Object> formData = (Map<String, Object>) data.getFormData();
        this.setInstanceId(data.getFormInstId());
        this.setInventory(BigDecimal.valueOf(((Number) formData.getOrDefault("numberField_lbbzp1q2", 0D)).doubleValue()));
        this.setMerchantCode((String) formData.get("textField_lbbzp1px"));
        this.setWarehouseName((String) formData.get("textField_lbbzp1q3"));
    }

}
